package io.jnet.client.client.impl;

import java.nio.channels.AsynchronousChannelGroup;
import java.nio.channels.AsynchronousSocketChannel;
import java.util.concurrent.BlockingQueue;
import io.jnet.client.build.ClientChannelContextBuilder;
import io.jnet.client.build.ClientChannelContextConfig;
import io.jnet.client.clientchannelcontext.ConcentrationClientChannelContext;
import io.jnet.common.api.ChannelContext;
import io.jnet.common.streamprocessor.ProcessorTask;
import io.jnet.common.util.AioListener;

public class ConcentrationClient extends AbstractClient
{
    private final BlockingQueue<ProcessorTask> taskQueue;
    
    public ConcentrationClient(BlockingQueue<ProcessorTask> taskQueue, ClientChannelContextBuilder clientChannelContextBuilder, AsynchronousChannelGroup channelGroup, String serverIp, int port, AioListener aioListener)
    {
        super(clientChannelContextBuilder, channelGroup, serverIp, port, aioListener);
        this.taskQueue = taskQueue;
    }
    
    @Override
    protected ChannelContext parse(ClientChannelContextConfig config, AsynchronousSocketChannel socketChannel, AioListener listener)
    {
        return new ConcentrationClientChannelContext(taskQueue, config.getMaxMerge(), config.getBufStorage(), config.getOutProcessors(), socketChannel, aioListener, config.getInProcessors(), config.getFrameDecodec());
    }
    
}
